<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     default_default
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
?>
<?php
    $merchandiserValues = $this->getCurrentCategoryValues();

    $smartAttribute_data_form = new Varien_Data_Form();
    $smartAttribute_data_form->setHtmlIdPrefix('smartmerch_');

    $form_renderer = Mage::getBlockSingleton('merchandiser/adminhtml_system_config_form_field_attributes');

    $form_fieldset = $smartAttribute_data_form->addFieldset('attributes_fieldset', array(
        'legend' => Mage::helper('merchandiser')->__('Smart Category: Select the attributes to use')
    ));

    $smart_cat_attr = $this->getSmartCategoryAttributes($merchandiserValues);

    $form_fieldset->addField('attributes', 'text', array(
        'name' => 'smartmerch_attributes',
        'title' => Mage::helper('merchandiser')->__('Attributes'),
        'value' => $smart_cat_attr,
    ))->setRenderer($form_renderer);
?>
<input type="hidden" id="category_id" value="<?php echo $this->getCategory()->getId() ?>" />
<div class="entry-edit visualmerch-content">
    <div class="entry-edit-head">
        <h4 class="icon-head head-edit-form fieldset-legend">
            <?php echo Mage::helper('merchandiser')->__("Visual Merchandiser") ?>
        </h4>
    </div>
    <div id="merchnadiser_attributes_fieldset" class="fieldset ">
        <div class="hor-scroll">
            <button style="" onclick="alertMessage(); vmopenedit.openPopup()" class="scalable merchandiser" type="button" title="<?php echo Mage::helper('merchandiser')->__("Show Visual Merchandiser") ?>" id="merchandiser.open.button">
                <span>
                    <span>
                        <span><?php echo Mage::helper('merchandiser')->__("Show Visual Merchandiser") ?></span>
                    </span>
                </span>
            </button>
        </div>
    </div>
</div>
<div class="smartmerch-content">
    <div class="box-left">
        <div class="entry-edit">
            <div class="entry-edit-head">
                <h4 class="icon-head head-edit-form fieldset-legend">
                    <?php echo Mage::helper('merchandiser')->__("Options") ?>
                </h4>
            </div>
            <div id="merchnadiser_attributes_fieldset" class="fieldset ">
                <div class="hor-scroll">
                    <table class="form-list">
                        <tr>
                            <td colspan="2" class="mer-mode"><label class="merchandiser-option-lable"><?php echo Mage::helper('merchandiser')->__("Only include products matched by rules") ?> :</label>
                                <select name="merchandiser[ruled_only]" id="group_198merchandise_option" class="select">
                                    <option value="0" <?php echo $merchandiserValues['ruled_only'] == 0 ? "selected='selected'" : "";?>><?php echo Mage::helper('merchandiser')->__("No") ?></option>
                                    <option value="1" <?php echo $merchandiserValues['ruled_only'] == 1 ? "selected='selected'" : "";?>><?php echo Mage::helper('merchandiser')->__("Yes") ?></option>
                                </select>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <?php echo Mage::helper('merchandiser')->__("Hero Products") ?> :
                            </td>
                            <td class="value">
                                <input type="text" class="input-text" value="<?php echo $merchandiserValues['heroproducts']; ?>" id="group_198merchandiser_heroproducts" name="merchandiser[heroproducts]" style="width:350px" />
                                <p class="note">
                                    <?php echo $this->__("Enter a comma separated list of SKUs that will always be displayed at the top of your category") ?>
                                </p>
                            </td>
                        </tr>
                        <tr>
                            <td class="label">
                                <?php echo Mage::helper('merchandiser')->__("Automatic sort") ?> :
                            </td>
                            <td class="value">
                                <select name="merchandiser[automatic_sort]" id="automatic_sort">
                                    <option value="none"><?php echo $this->__("None") ?></option>
                                    <?php foreach (Mage::helper('merchandiser')->getConfigAction() as $action_index => $action): ?>
                                        <option value="<?php echo $action_index ?>" <?php echo $merchandiserValues['automatic_sort'] == $action_index ? "selected='selected'" : ""; ?> >
                                            <?php echo $action['name'] ?>
                                        </option>
                                    <?php endforeach; ?>
                                </select>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <input type="hidden" value="<?php echo $this->getCategory()->getMerchandiserSortingOptions(); ?>" id="group_198merchandiser_sorting_options" name="general[merchandiser_sorting_options]" />
    <div class="box-right">
        <div class="entry-edit  attribute-map"><?php echo $smartAttribute_data_form->toHtml(); ?></div>
    </div>
</div>

<?php if (Mage::helper('merchandiser')->isHideProductPositionField()): ?>
    <style>#catalog_category_products_table tbody tr td.editable .input-text { visibility:hidden; }</style>
<?php endif; ?>

<script type="text/javascript">
    //<![CDATA[
    function submitCategory(value, savedValue) {
        if (value == 1 && savedValue == 2) {
            categorySubmit('<?php echo Mage::helper('adminhtml')->getUrl('*/catalog_category/save', array('isAjax' => 'true', 'id' => $this->getCategory()->getId())) ?>' , true);
        }
    }

    var vmopenedit = new vmOpenEdit();
    $$('select.logic_link').each(function(item, index) {
        if (index == $$('select.logic_link').length -1) {
            item.hide();
        } else {
            item.show();
        }
    });

    function alertMessage() {
        if ($('automatic_sort').value != 'none') {
            alert('<?php echo Mage::helper('core')->jsQuoteEscape($this->__('Please note, this category is set to automatically sort. Any drag-and-drop positions will be reset.')) ?>');
        }
    }
    //]]>
</script>
